import os
from abc import ABCMeta, abstractmethod
from ris_tag.settings import *

env = os.environ.get('RIS_TAG_ENV', 'Dev')
ENV_CONF = eval('%sConfig'%env.capitalize())

class Base():
    __metaclass__ = ABCMeta

    def __init__(self):
        self.db = ENV_CONF.MONGO_DB
        self.collection = self.db['users']

    def find(self, query):
        '''
        :param query: dict
        :return:
        '''
        result = self.collection.find(query)
        return list(result)

    def update_one(self, query, set_dict, upsert=False):
        '''
        :param query: dict
        :param set_dict: dict
        :param upsert: bool
        :return:
        '''
        result = self.collection.update_one(query, {'$set': set_dict}, upsert)
        return result

    def insert_one(self, data):
        print(data)
        print(type(data))
        result = self.collection.insert_one(data)
        print('here')
        return result